
	mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						auto:false,
						contentrefresh: '正在加载...',
						callback: pullupRefresh
					}
				}
	});
	
	
	var userinfo = app.getState() || {};
    var uid = userinfo.user_id;
    var currenPage=1;
    var pageSize=6;
    var total_page=0;
    var total_count=0;
    var store_id=0;
    
    window.onload = function(){
    	
		mui.plusReady(function() {
		 	//关闭等待框
		 	plus.nativeUI.closeWaiting();
		 	//显示当前页面
		 	mui.currentWebview.show();
		
		 	store_id = plus.webview.currentWebview().store_id;
		 	var store_name = plus.webview.currentWebview().store_name;
		 	document.getElementById('store_name').innerHTML = store_name;
		
		 	mui.ajax({
		 		url: apiurl + "Store/goods_list/",
		 		data: {'p': currenPage,'size': pageSize,'store_id': store_id,'_token':userinfo.token},
		 		async: true,
		 		dataType: 'json',
		 		crossDomain: true, //强制使用5+跨域
		 		type: 'get',
		 		timeout: 10000,
		 		success: function(res) {
		 			console.log(JSON.stringify(res));
		 			// 请求成功
		 			if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
		 				total_page = res.total_page;
		 				total_count = res.sum;
		 				var htm = get_data(res.resource);
		 				$('#pullrefresh .mui-scroll .mui-table-view').append(htm);
		 			}
		 		},
		 		error: function(xhr, type, errorThrown) {
		 			//console.log(JSON.stringify(xhr));
		 			//console.log(JSON.stringify(type));
		 			//console.log(JSON.stringify(errorThrown));
		 			mui.toast('获取数据失败！');
		 		}
		 	});
		 	
		 	mui(".mui-table-view").on('tap','.mui-table-view-cell .see_good',function(){
				var goods_id = this.getAttribute("data-id");
				mui.openWindow({
				    id:'commodity_detail.html',
				    url:'commodity_detail.html',
				    createNew:true,
				    extras:{
				       goods_id:goods_id //自定义扩展参数，可以用来处理页面间传值
				    },
				    show: {
						autoShow:false
					},
					waiting: {
						autoShow: true,
						title:'正在加载...'
					}
			  	});
			}) 

		 });
    }

    function get_data(data){
    	var htm='';
		for(i in data) {
			/*
			 * <li class="mui-table-view-cell"">
						<a>
							<div class="commodity_img"><img src="../../img/shop.png"></div>
							<div class="commodity_main">
								<p>苹果iphone7 全网通4G手机</p>
								<h5>5692</h5>
							</div>
						</a>
					</li>
			 */
			htm += '<li class="mui-table-view-cell">';
			htm+='<a class="see_good" data-id="'+data[i]['goods_id']+'">';
			htm+='<div class="commodity_img">';
			if(data[i]['original_img'].indexOf(upurl+'Uploads') !== -1){
				var img_path=data[i]['original_img'];
			}
			else{
				var img_path=upurl+data[i]['original_img'];
			}
			htm+='<img src="'+img_path+'">';
			htm+='</div>';
			htm+='<div class="commodity_main">';
			htm+='<p>'+data[i]['goods_name']+'</p>';
			htm+='<h5>'+data[i]['shop_price']+'</h5>';
			htm+='</div>';
			htm+='</a>';
			htm+='</li>';
		}
		return htm;
    }


	function pullupRefresh() {
		setTimeout(function() {
			currenPage++;
			mui.ajax({
				url: apiurl + "Store/goods_list/",
				data: {'p':currenPage,'size':pageSize,'store_id': store_id,'_token':userinfo.token},
				async: true,
				dataType: 'json',
				crossDomain: true, //强制使用5+跨域
				type: 'get',
				timeout: 10000,
				success: function(res) {
					console.log(JSON.stringify(res));
					// 请求成功
					if(res.status ==-3){
						mui.toast(res.msg);
						app.out();
						return false;
					} else {
						var htm=get_data(res.resource);
						$('#pullrefresh .mui-scroll .mui-table-view').append(htm);
					}
					
					if(currenPage < total_page){
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);    /*能上拉*/
	                }else{
	                    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);/*不能上拉*/
	                }
				},
				error: function(xhr, type, errorThrown) {
					//console.log(JSON.stringify(xhr));
					//console.log(JSON.stringify(type));
					//console.log(JSON.stringify(errorThrown));
					mui.toast('获取数据失败！');
				}
			});
			
		}, 1500);
	}
	

	function see_good(goods_id){
		mui.openWindow({
			    id:'commodity_detail.html',
			    url:'commodity_detail.html',
			    createNew:true,
			    extras:{
			       goods_id:goods_id //自定义扩展参数，可以用来处理页面间传值
			    },
			    show: {
					autoShow:false
				},
				waiting: {
					autoShow: true,
					title:'正在加载...'
				}
		  	});
	}